<?php
/**
 * Created by PhpStorm.
 * User: jwb
 * Date: 2020/9/17
 * Time: 9:25
 */

namespace App\Services;

use App\Goods;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Grid\Tools\BatchActions;
use Encore\Admin\Grid\Tools\Selector;
use Encore\Admin\Show;
use Encore\Admin\Widgets\Tab;

class GoodsService
{

    public function gridColumn(\Encore\Admin\Grid $grid)
    {
        $that = $this;
        $grid->column('patent_sn', __('Patent sn'));
        $grid->column('patent_name', __('Patent name'))->modal('详情', function ($model) use ($that) {
            return $that->detail($model);
        });
        $grid->column('type.name', __('专利类型'));
        $grid->column('inventor', __('Inventor'));
        $grid->column('patent_person', __('专利权人'))->hide();
        $grid->column('apply_date', __('Apply date'))->hide();
        $grid->column('sale_mode', __('转化类型'))->display(function ($sale_mode) {
            return implode($sale_mode, ',');
        });
        $grid->column('amount', __('转化金额'));
        $grid->column('user.name', __('负责人'));
        $grid->batchActions(function (BatchActions $actions) {
            $actions->disableDeleteAndHodeSelectAll();
        });
        return $grid;
    }

    public function detail(Goods $model)
    {
        $tab = new Tab();
        $tab->add('基本信息', Admin::show($model, function (Show $show) {
            $show->panel()->view('show.tab-panel');
            $show->field('patent_sn', __('Patent sn'));
            $show->field('patent_name', __('Patent name'));
            $show->field('type.name', __('专利类型'));
            $show->field('department.name', __('所属部门'));
            $show->field('patent_person', __('专利权人'));
            $show->field('inventor', __('Inventor'));
            $show->field('apply_date', __('Apply date'));
            $show->field('sale_mode', __('转化类型'))->as(function ($sale_mode) {
                return implode($sale_mode, ',');
            });
            $show->field('amount', __('转化金额'));
            $show->field('state', __('状态'))->using(['待发布', '已上架', '已售出', '已下架']);
        }));
        $tab->add('负责人', Admin::show($model, function (Show $show) {
            $show->panel()->view('show.tab-panel');
            $show->field('user.name', __('姓名'));
            $show->field('user.mobile', __('电话'));
            $show->field('user.email', __('邮箱'));
        }));
//        $tab->add('提交人', Admin::show($model, function (Show $show) {
//            $show->panel()->view('show.tab-panel');
//            $show->field('creator.name', __('姓名'));
//            $show->field('creator.mobile', __('电话'));
//            $show->field('creator.email', __('邮箱'));
//        }));

        $style = <<<STYLE
.nav-tabs-custom>.nav-tabs {
        border-bottom-color: #3c8dbc;
    }
    .nav-tabs-custom>.nav-tabs>li.active>a {
        border-left-color: #3d6e8a;
        border-right-color: #3d6e8a;
    }
STYLE;
        Admin::style($style);
        return $tab;
    }


}